// File [test/stdx/memory/02/main.cpp].
// (c) Copyright Alf P. Steinbach 2008.

/*
    Testing alfs::static_move_ptr

    Expected: compiles cleanly, with

    <output>
        Constructed
        Custom deleter invoked
        Destroyed
    </output>

    With "#if 1" changed to "#if 0", should not compile, but instead report
    error on attempt to delete instance of incomplete type.
*/

#include    <alfs/stdx/memory.hpp>
#include    <alfs/bundled_lib/move_ptrs.hpp>
#include    <iostream>

static void say( char const s[] ) { std::cout << s << std::endl; }

struct Foo;

Foo* newFoo();
void destroy( Foo* p );

#if 1
namespace std {
    template<>
    struct default_delete<Foo>
    {
        void operator()( Foo* p ) const
        {
            say( "Custom deleter invoked" );
            destroy( p );
        }
    };
}  // std
#endif

int main()
{
    alfs::jt::static_move_ptr<Foo>    p( newFoo() );
}
